local blaze = require "blaze"
local game = require "club.threecard.texas"

local M = game.ui.activity()

function M:ctor()
    self.res = "club.threecard.texas/ui/ingame.b:ingame"

    self.public_card = game.require("ui.ingame.public_card").new()
    self.seats = game.require("ui.ingame.seats").new()
    self.dealer = game.require("ui.ingame.dealer").new(self)
    self.button_tag = game.require("ui.ingame.button_tag").new(self)
    self.operator = game.require("ui.ingame.operator").new()
    self.result_shower = game.require("ui.ingame.result_shower").new(self)
    self.bonus_pool = game.require("ui.ingame.bonus_pool").new()
    self.hand_tip = game.require("ui.ingame.hand_tip").new()
    self.resumer = game.require("ui.ingame.resumer").new()
    self.server_time = require("ui.widgets.ServerTime").new()
    self.network_signal = require("ui.widgets.NetworkSignal").new()

    self.result_shower:hide()
    self.operator:hide()
    self.button_tag:hide()
    self.hand_tip:hide()
end

function M:on_load()
    self:super("on_load")
    self.dealer:load()
    self.public_card:load()
    self.seats:load()
    self.button_tag:load()
    self.operator:load()
    self.result_shower:load()
    self.bonus_pool:load()
    self.hand_tip:load()
    self.resumer:load()

    self.dealer:set_parent(self.delaer_root, false)
    self.public_card:set_parent(self.public_card_root, false)
    self.seats:set_parent(self.seat_root, false)
    self.button_tag:set_parent(self.button_tag_root, false)
    self.operator:set_parent(self.operator_root, false)
    self.result_shower:set_parent(self.result_shower_root, false)
    self.bonus_pool:set_parent(self.bonus_root, false)
    self.hand_tip:set_parent(self.hand_tip_root, false)
    self.resumer:set_parent(self.resumer_root, false)

    game.store.ingame.throttle(false)
end

function M:on_injected(bind)
    bind("button.click", self.exit_btn, self.on_exit_game)
    bind("shortcut.escape", self.exit_btn.gameObject, self.on_exit_game)
    bind("button.click", self.help_btn, self.on_help)
    bind("gameobject.element", self.network_signal_obj, self.network_signal)
    bind("gameobject.element", self.server_time_obj, self.server_time)
end

function M:on_exit_game()
    game.audio.post("texas:click")
    game.game_scene.leave()
end

function M:on_help()
end

return M